using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using RssReader.Data;

namespace RssReader
{
	public partial class DetailsViewController : UIViewController
	{
		#region Constructors

		// The IntPtr and NSCoder constructors are required for controllers that need 
		// to be able to be created from a xib rather than from managed code

		public DetailsViewController (IntPtr handle) : base(handle)
		{
			Initialize();
		}

		[Export("initWithCoder:")]
		public DetailsViewController(NSCoder coder) : base(coder)
		{
			Initialize();
		}

		public DetailsViewController() : base("DetailsViewController", null)
		{
			Initialize();
		}

		void Initialize()
		{
		}
		
		#endregion
		
		public Database.ArticlesRow CurrentArticle;
		
		public override void ViewWillAppear(bool animated)
		{
			base.ViewWillAppear(animated);
			BindItem();
		}
		
		private void BindItem()
		{
			headlineLabel.Text = CurrentArticle.Title;
			dateLabel.Text = CurrentArticle.PubDate.ToLongDateString() + "  " + CurrentArticle.PubDate.ToLongTimeString();
			webView.LoadHtmlString(CurrentArticle.Description, new NSUrl(CurrentArticle.Link, false));
		}
	}
}